home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / ORD_TEXT.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  720b  |  35 lines

  1. /*
  2. **  Originally published as part of the MicroFirm Function Library
  3. **
  4. **  Copyright 1991, Robert B.Stout
  5. **
  6. **  Subset version with modifications suggested by Maynard Hogg
  7. **  released to the public domain, 1992
  8. **
  9. **  Function to return ordinal text.
  10. */
  11.  
  12. static char *text[] = {"th", "st", "nd", "rd"};
  13. static int index[]  = {0, 1, 2, 3, 0, 0, 0, 0, 0, 0};
  14.  
  15. char *ordinal_text(int number)
  16. {
  17.       if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
  18.             number = 0;
  19.       return text[number];
  20. }
  21.  
  22. #ifdef TEST
  23.  
  24. #include <stdio.h>
  25.  
  26. void main(void)
  27. {
  28.       int i;
  29.  
  30.       for (i = 0; i < 26; ++i)
  31.             printf("%d%s\n", i, ordinal_text(i));
  32. }
  33.  
  34. #endif /* TEST */
  35.